package com.rh.bmw4s.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.rh.bmw4s.R;
import com.rh.bmw4s.bean.CarBean;
import com.rh.bmw4s.utills.glide.GlideImageLoader;

/**
 * Created by Administrator on 2017/9/28.
 */

public class CarAdapter extends ListBaseAdapter<CarBean> {

    private int extars = 0; //10 全局搜索时用到   0 二手车 1 新车 3 用品 4轮胎 (用的都是这个adapter，特惠 热销 价格展示要区分好)
    private GlideImageLoader imageLoader;

    public CarAdapter(Context context) {
        super(context);
        imageLoader = new GlideImageLoader(context);
    }

    public CarAdapter(Context context, int extars) {
        super(context);
        this.extars = extars;
        imageLoader = new GlideImageLoader(context);
    }


    @Override
    public int getLayoutId() {
        return R.layout.item_car;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, int position) {
        final CarBean bean = getDataList().get(position);
        LinearLayout linearLayout = holder.getView(R.id.ll_newcar_item);
        ImageView imgHead = holder.getView(R.id.img_head);
        ImageView imgHotLabel = holder.getView(R.id.img_hot_label);  //热销角标
        ImageView imgOddsLabel = holder.getView(R.id.img_odds_label);  //特惠角标
        TextView tvTitle = holder.getView(R.id.tv_title);
        TextView tvPrice = holder.getView(R.id.tv_price);
        //-------------------显示角标-----------------------
        if (extars == 4) { //轮胎 特惠
            if (bean.getIs_special() == 1) {
                //显示角标
                imgOddsLabel.setVisibility(View.VISIBLE);
            } else {
                imgOddsLabel.setVisibility(View.GONE);
            }
            imgHotLabel.setVisibility(View.GONE);
        } else if (extars == 0 || extars == 1) { //二手车 新车 热销
            if (bean.getIs_hot() == 1) {
                //显示角标
                imgHotLabel.setVisibility(View.VISIBLE);
            } else {
                imgHotLabel.setVisibility(View.GONE);
            }
            imgOddsLabel.setVisibility(View.GONE);
        } else { //汽车用品
            imgHotLabel.setVisibility(View.GONE);
            imgOddsLabel.setVisibility(View.GONE);
        }
        //-------------------显示角标-----------------------
        imageLoader.display(imgHead, bean.getLogo());

        tvTitle.setText(bean.getGoods_name());

        //-------------------显示价格-----------------------
        tvPrice.setText(bean.getShop_price() + "万");
//        if (extars == 3 || extars == 4) {
//            //汽车轮胎和用品价格显示
//            tvPrice.setText(bean.getLunyong() + "万");
//        } else if (extars == 0) {
//            //二手车价格显示
//            tvPrice.setText(bean.getMarket_price() + "万");
//        } else {
//            //新车价格显示
//            tvPrice.setText(bean.getShop_price() + "万");
//        }
        //-------------------显示价格-----------------------
    }
}
